
var $table = $('#table');
var state = "load";
var TableInit=function(){
    var oTableInit = new Object();
    oTableInit.Init=function() {
        $(document).on('focus', 'input[type="text"]', function () {
            $(this).parent().find('label').addClass('active');
        }).on('blur', 'input[type="text"]', function () {
            if ($(this).val() === '') {
                $(this).parent().find('label').removeClass('active');
            }
        });
        $table.bootstrapTable({
            url: '/manager/managers/allManager?act=load',
/*            url:'../js/data.json',*//*
            url: "<c:url value='/manager/managers/allManager?act="+state+"'/>", //获取数据的Servlet地址*/
            method : 'get', // 请求方式（*）post/get
            contentType: "application/x-www-form-urlencoded",
            queryParams: function queryParams(params) {   //设置查询参数
                return {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                };
            },

            height: getHeight(),
            striped: true,
            silent: true,
            searchOnEnterKey: true,
            showRefresh: true,
            showToggle: true,
            showColumns: true,
            minimumCountColumns: 2,
            showPaginationSwitch: true,
            clickToSelect: true,
            detailView: true,
            detailFormatter: 'detailFormatter',
            pagination: true,
            paginationLoop: false,
            classes: 'table table-hover table-no-bordered',
            smartDisplay: false,
            sortName: 'id',
            sortOrder: 'desc',
            escape: true,
            idField: 'systemId',
            maintainSelected: true,
            pageNumber : 1, // 初始化加载第一页，默认第一页
            pageSize : 10, // 每页的记录行数（*）
            pageList : [ 10, 25, 50, 100 ],
            toolbar: '#toolbar',
            columns: [
                {field: 'state', checkbox: true},
                {field: 'id', title: '编号', sortable: true, halign: 'center'},
                {field: 'username', title: '账号', sortable: true, halign: 'center'},
                {field: 'password', title: '密码', sortable: true, halign: 'center'},
                {field: 'sex', title: '性别', sortable: true, halign: 'center'},
                {field: 'phone', title: '手机', sortable: true, halign: 'center'},
                {field: 'email', title: '邮箱', sortable: true, halign: 'center'},
                {field: 'remark', title: '权限', sortable: true, halign: 'center'},
                {field: 'action', title: '操作', halign: 'center', align: 'center', formatter: 'actionFormatter', events: 'actionEvents', clickToSelect: false}
            ],
        }).on('all.bs.table', function (e, name, args) {
            $('[data-toggle="tooltip"]').tooltip();
            $('[data-toggle="popover"]').popover();
        });
    };
        oTableInit.destroy=function(){
            $("#reportTable").bootstrapTable('destroy');
        }
        return oTableInit;
    }
    var oTable = new TableInit();//新定义一个表格
    oTable.destroy();//如果之前存在，则先毁灭
    oTable.Init();//初始化表格

function actionFormatter(value, row, index) {
    return [
        '<a class="edit ml10" href="/manager/managers/allManager?act=edit&&userid='+row.username+'" data-toggle="tooltip" title="Edit"><i class="glyphicon glyphicon-edit"></i></a>　',
        '<a class="remove ml10" href="/manager/managers/allManager?act=del&&userid='+row.username+'" data-toggle="tooltip" title="Remove"><i class="glyphicon glyphicon-remove"></i></a>'
    ].join('');
}

window.actionEvents = {
    'click .edit': function (e, value, row, index) {
        console.log(value, row, index);
    },
    'click .remove': function (e, value, row, index) {
        alert('删除成功');
        console.log(value, row, index);
    }
};

function detailFormatter(index, row) {
    var html = [];
    $.each(row, function (key, value) {
        html.push('<p><b>' + key + ':</b> ' + value + '</p>');
    });
    return html.join('');
}

// 新增
function createAction() {
    $.confirm({
        type: 'dark',
        animationSpeed: 300,
        title: '新增管理员',
        content: $('#createDialog').html(),
        buttons: {

            cancel: {
                text: '取消',
                btnClass: 'waves-effect waves-button'
            }
        }
    });
}
